cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-04 LANGUAGES C CXX Fortran)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSION OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FortranCInterface)
FortranCInterface_VERIFY(CXX)                   # 验证Fortran能够和C/C++混合编译
FortranCInterface_HEADER(fc_mangle.h            # 生成头文件　fc_mangle.h ，包括宏名和符号DSCAL DGESV
        MACRO_NAMESPACE "FC_"
        SYMBOLS DSCAL DGESV)

find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

add_library(math "")
target_sources(math PRIVATE CxxBLAS.cpp CxxLAPACK.cpp)
target_include_directories(math PUBLIC ${CMAKE_CURRENT_BINARY_DIR})     # 需要包含生成的fc_mangle.h
target_link_libraries(math PUBLIC ${LAPACK_LIBRARIES})

# 可执行目标并链接 math
add_executable(linear-algebra linear-algebra.cpp)
target_link_libraries(linear-algebra PRIVATE math)
